unit VDGOSpecRepo;

interface

uses System.SysUtils, System.Variants,
     Data.DB,
     uADCompClient,
     ManagerDB;

type
{ TVDGOSpecRepo }

  TVDGOSpecRepo = class(TObject)
  private
    fManager: TManagerDB;
    fDS: TADQuery;
    fSelectQuery: string;
  protected

  public
    constructor Create;
    destructor Destroy; override;
    //
    function LoadData(const clause: string): Boolean;
  published
    property DS: TADQuery read fDS;
  end;

implementation

{ TVDGOSpecRepo }

constructor TVDGOSpecRepo.Create;
begin
  fManager:= TManagerDB.Create;
  //prepare DataSet
  fSelectQuery:= 'SELECT VS.HOUSE, VS.FLATCNT, VS.F1, VS.F2, VS.F3, VS.F4, VS.F5, VS.F6,'+#10#13+
                 '       VS.F7, VS.F8, VS.F9, VS.F10, VS.F11, VS.F12'+#10#13+
                 '       ,H.NOMER, S.NAME STREETNAME'+#10#13+
                 'FROM VDGO_SPEC VS'+#10#13+
                 'LEFT OUTER JOIN HOUSE H ON H.CODE = VS.HOUSE'+#10#13+
                 'LEFT OUTER JOIN STREET S ON S.CODE = H.STREET'+#10#13+
                 '&Where'+#10#13+
                 '&Order';
  fDS:= fManager.SetWriteOptions(False, fSelectQuery,'VDGO_SPEC','HOUSE','');
  fDS.MacroByName('Order').AsRaw:='ORDER BY S.NAME, H.NOMER';
end;

destructor TVDGOSpecRepo.Destroy;
begin
  if Assigned(fManager) then
     FreeAndNil(fManager);
  inherited;
end;

function TVDGOSpecRepo.LoadData(const clause: string): Boolean;
begin
  with fDS do begin
    Close;
    if clause<>'' then
      MacroByName('Where').AsRaw:='Where '+clause;
    Open;
  end;
  Result:= True;
end;

end.
